package pl.prv.polanie.client.panels.lists;

import pl.prv.polanie.client.dialogs.CreateRoomDialog;
import pl.prv.polanie.client.dto.CSRoomDTO;
import pl.prv.polanie.client.dto.CSVRoomDTO;
import pl.prv.polanie.client.model.Cache;
import pl.prv.polanie.client.model.ViewDataProvider;
import pl.prv.polanie.client.widgets.table.TableRooms;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Widget;

public class RoomsList extends ObjectsList {

	TableRooms tableRooms = new TableRooms(this);

	public RoomsList() {
		
		CSRoomDTO[] ls = Cache.getAllRooms();
		//AcademicTitleDTO[] ats = Cache.getAllAcademicTitles();
		
		add(tableRooms);
		
		
		for (int i = 0; i < ls.length; i++) {
			
			CSRoomDTO cs = ls[i];
			CSVRoomDTO csv = ViewDataProvider.getCSVRoom(cs);
			
			tableRooms.addRow(cs, csv);
		}
		
		
		addRecordButton.addClickListener(new ClickListener(){
			public void onClick(Widget sender) {
				CreateRoomDialog cld = new CreateRoomDialog(RoomsList.this, null); 
				cld.center();
			}
		});
		
		removeSelectedRecordButton.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				tableRooms.removeSelectedRoomFromTable();
			}
		});
		
		setupButtons();
	}
	
	public void addCSRoom(CSRoomDTO csRoom) {
		tableRooms.saveOrUpdateRoomInTable(csRoom);
	}

}
